# 作者：苏子铭
# 时间：2021/10/28   21:59
# graph = {
#     'A': ['B', 'S'],
#     'B': ['A'],
#     'C': ['D', 'E', 'F', 'S'],
#     'D': ['C'],
#     'E': ['C', 'H'],
#     'F': ['C', 'G'],
#     'G': ['F', 'S'],
#     'H': ['E', 'G'],
#     'S': ['A', 'C', 'G']
# }
# visited = []
# def dfs(graph, node):
#     global visited
#     if node not in visited:
#         visited.append(node)
#         for n in graph[node]:
#             dfs(graph, n)
# dfs(graph, 'A')
# print(visited)
# import random
# def bubbleSort(a):
#     for i in range(len(a)-1, -1, -1):           #这里从最后一个到倒数第二个循环，外循环是循环每个数与剩下的数比较
#         for j in range(i):                      #内循环是轮到哪个数那个数与它前面的数比较
#             if a[j] > a[j+1]:                   #如果循环到的数较大，那就交换，大数往后放。
#                 a[j], a[j+1] = a[j+1], a[j]
# def main():
#     su121 = []
#     for i in range(10):
#         su121.append(random.randint(21, 99))
#     print(su121)
#     bubbleSort(su121)
#     print(su121)
# if __name__ =='__main__':main()
# import random
# def selectSort(a):
#     for i in range(0, len(a)):    #range不选结束项，不需要-1，若先选最大值换成（len(a)-1,-1,-1）即可。
#         min = i                   #暂定最小值的下标为所选的数i的下标，再内循环用min与后面的数一一比较，小数值的往前放
#         for j in range(i+1, len(a)):#再外循环时min就会往下走，不影响已经选好的最小值
#             if a[min] > a[j]:
#                 min = j           #把最小的数下标赋给min，a[min]最小就和初识a[i]换，最小数放前面
#                 a[min], a[i] = a[i], a[min]
#
# def main():
#     su121 = []
#     for i in range(10):
#         su121.append(random.randint(21, 99))
#     print(su121)
#     selectSort(su121)
#     print(su121)
# if __name__ == '__main__': main()
# import random
#
# def quickSort(a, left, right):
#     i = left
#     j = right
#     key = a[i]
#     if i >= j:
#         return a                #当i>=j时，快排结束
#     while i < j:
#         while i < j and a[j] >= key:        #内循环只是把第一个key值确定位置，左边比key小，右边比key大，但两边未排序。
#             j -= 1                          #故需要外循环结合70与71行，多次排列，直到i>=j,排序结束
#         a[i] = a[j]                             #内循环while结束才把j值赋值给i，因为a[i]值被保存于key，这里只能先从后开始，
#         while i < j and a[i] <= key:            # 若从前面开始则要key=a[j],才保证有值没有值没有丢失；
#             i += 1                              #63和66行，必须有等于号，否则a[i]或a[j]被赋值后的值和key若相等，则进入死循环。
#         a[j] = a[i]
#     a[i] = key
#     quickSort(a, left, i-1)
#     quickSort(a, j+1, right)            #更换上下界，循环排序。
#
# def binarySearch(key, a):
#     left = 0
#     right = len(a)-1
#     while left <= right:
#         mid = (left + right)//2         #mid要在循环里面，因为最大最小值会变，故中间值不唯一
#         if a[mid] < key:                #a[mid]小就找左侧，调整右边上界限
#             right = mid - 1
#         elif a[mid] > key:              #a[mid]大就找右侧，调整下界限
#             left = mid + 1
#         else:
#             return mid
#     return 0
#
# def main():
#     su121 = [random.randint(0, 51) for i in range(20)]      #链式直接输出list从1-51的20个随机数
#     print(su121)
#     quickSort(su121, 0, len(su121)-1)
#     print(su121)
#     key = binarySearch(21, su121)
#     print("索引的值：", key)
# if __name__ == "__main__":main()



su121 = {
    '1': ['2', '3'],
    '2': ['4', '5'],
    '3': ['6', '7'],
    '4': ['2', '8'],
    '5': ['2', '8'],
    '6': ['3', '7'],
    '7': ['3', '6'],
    '8': ['4', '5']
}
visited = []
def dfs(su121, node):
    global visited
    if node not in visited:
        visited.append(node)
        for n in su121[node]:
            dfs(su121, n)
dfs(su121, '1')
print(visited)